diff --git a/assets/img/avatars/128/mouse.png b/assets/img/avatars/128/mouse.png new file mode 100644 index 0000000..9b75967 Binary files /dev/null and b/assets/img/avatars/128/mouse.png differ diff --git a/assets/img/avatars/32/asterix.png b/assets/img/avatars/32/asterix.png new file mode 100644 index 0000000..1dc99b1 Binary files /dev/null and b/assets/img/avatars/32/asterix.png differ diff --git a/assets/img/avatars/32/mouse.png b/assets/img/avatars/32/mouse.png new file mode 100644 index 0000000..3177e4d Binary files /dev/null and b/assets/img/avatars/32/mouse.png differ diff --git a/config.php b/config.php index 287a7cd..b3ab033 100644 --- a/config.php +++ b/config.php @@ -8,7 +8,7 @@ error_reporting(E_ALL); session_start(); -define('DEFAULT_RADIUS', 50); +define('DEFAULT_RADIUS', 10); define('TAILLE_SPRITE', 32); define('DEMI_TAILLE_SPRITE', (TAILLE_SPRITE/2)); @@ -44,13 +44,16 @@ class Player { $players = [ + new Player('2iqUybqeYhX2MvNVZsKYQ59FNAm6wAukpUsfJKFsC4Aw', 'Joe (Astérix)'), + new Player('FR1UMmvimmxEBeghy1Fsizqen3Wse5hYUZU9VnHFPtN8', 'Eva Zykejtepousse'), + new Player('QP1VkfaFUMdHZmHgPMi7q5wJJHaQhZcEqs5A86NigKr', 'Toto du 56'), + new Player('7jikBcC2Cd89SGGDuMXNPqyBXn2FeBFY1XnKAQgyAxeA', 'Astronaut astro'), new Player('2L8vaYixCf97DMT8SistvQFeBj7vb6RQL7tvwyiv1XVH', 'Fred'), new Player('25zB1gSC7Qhwnx463cuDLDCKLRVieLAgFiPbYq6jVHG9', 'Boris'), new Player('u3rNW7CzqDC5V4L3FGVbSPsrBd78y8pkRACKHtBtCPx', 'Syoul'), new Player('8PTThXiUSwwuPoqQWw3tuAn4MpvzQzpKhs6LMuiozS7Z', 'kimamila') ]; - if (!isset($_SESSION['radius'])) { $_SESSION['radius'] = DEFAULT_RADIUS; @@ -70,16 +73,20 @@ $games = [ 'spationaute' => [ 'title' => 'SpaceĞ1', - 'description' => 'Les extraterrestres viennent terraformer ta planète' + 'description' => 'Les extraterrestres viennent terraformer ta planète', + 'default_avatar' => 'assets/img/avatars/32/et-in-flying-saucer.png' ], 'magie' => [ 'title' => 'Ğ1Quest', - 'description' => 'Ğarry Potier à l\'école des sourciers.' + 'description' => 'Ğarry Potier à l\'école des sourciers.', + 'default_avatar' => 'assets/img/avatars/32/wizard.png' ] ]; +$radiuses = [5, 10, 20, 50, 100]; + define('DEFAULT_GAME', 'spationaute'); if (!isset($_SESSION['gameId'])) { diff --git a/geoloc.php b/geoloc.php deleted file mode 100644 index c5b8ac5..0000000 --- a/geoloc.php +++ /dev/null @@ -1,35 +0,0 @@ - - -
--
- - - - \ No newline at end of file diff --git a/lib/Conversation.class.php b/lib/Conversation.class.php new file mode 100644 index 0000000..6217e90 --- /dev/null +++ b/lib/Conversation.class.php @@ -0,0 +1,91 @@ +getDate() < $msg2->getDate()) ? false : true; +} + +class Conversation { + + private $messages = []; + + private $firstMessage; + + private $lastMessage; + + private $convTitle; + + private $penpalPubkey; + + + + public function __construct () { + + } + + public function addMessage ($msg) { + + $this->messages[] = $msg; + + if (!isset($this->lastMessage, $this->firstMessage)) { + + $this->lastMessage = $msg; + $this->firstMessage = $msg; + + } else { + + if ($msg->getDate() > $this->lastMessage->getDate()) { + + $this->lastMessage = $msg; + } + + if ($msg->getDate() < $this->firstMessage->getDate()) { + + $this->firstMessage = $msg; + } + } + } + + public function sortMessages () { + + uasort($this->messages, 'compareMsgDate'); + + } + + public function getConvTitle () { + + if (!isset($this->convTitle)) { + + $this->convTitle = $this->getFirstMessage()->getTitle(); + } + + return $this->convTitle; + } + + public function getPenpalPubkey () { + + if (!isset($this->penpalPubkey)) { + + $this->penpalPubkey = $this->getFirstMessage()->getPenpalPubkey(); + } + + return $this->penpalPubkey; + } + + public function getMessages () { + + return $this->messages; + } + + public function getFirstMessage () { + + return $this->firstMessage; + } + + public function getLastMessage () { + + return $this->lastMessage; + } +} \ No newline at end of file diff --git a/lib/Fred.class.php b/lib/Fred.class.php index 4f8baae..8f2103c 100644 --- a/lib/Fred.class.php +++ b/lib/Fred.class.php @@ -40,28 +40,71 @@ class Fred { return $ipnsKey; } - public function donneMoiSesPutainDeMessagesGchange ($prenomNom, $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday, $gchangeId) { + public function donneMoiSesPutainDeMessagesGchange ($prenomNom, $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday, $gchangeName) { $salt = $prenomNom; $pepper = $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday; - $query = 'salt='. $salt .'&pepper='. $pepper . '&messaging=' . $gchangeId; + $query = 'salt='. $salt .'&pepper='. $pepper . '&messaging=' . $gchangeName; $url = $this->gatewayProtocol . '://'. $this->gatewayDomain .':' . $this->gatewayPort . '/?' . $query; - echo ''; var_dump(htmlspecialchars($url)); echo ''; + // echo '
'; var_dump(htmlspecialchars($url)); echo ''; $page1 = file_get_contents($url) or die('
On a fait du sale.
'); - echo ''; var_dump(htmlspecialchars($page1)); echo ''; + // echo '
'; var_dump(htmlspecialchars($page1)); echo ''; preg_match("`url='([^']+)'`isU", $page1, $matches); - $url = $matches[0]; + $url = $matches[1]; - echo '
'; var_dump($url); echo ''; + // echo '
'; var_dump($url); echo ''; + + $page2 = ''; + + while (empty($page2)) { + + sleep($this->gatewayDelay); + $page2 = @file_get_contents($url); + } + + // echo '
'; var_dump(htmlspecialchars($page2)); echo ''; + + $json = $page2; + + return json_decode($json); + + } + public function donneMoiSaPutaindeG1Pub ($prenomNom, $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday) { + + + $salt = $prenomNom; + $pepper = $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday; + + $query = 'salt='. $salt .'&pepper='. $pepper . '&g1pub=on'; + + $url = $this->gatewayProtocol . '://'. $this->gatewayDomain .':' . $this->gatewayPort . '/?' . $query; + + // echo '
'; var_dump(htmlspecialchars($url)); echo ''; + + $page1 = file_get_contents($url) + or die('
On a fait du sale.
'); + + // die('' . htmlspecialchars($page1) . ''); + + preg_match("`url='([^']+)'`isU", $page1, $matches); + + // die( + // '
' . htmlspecialchars($page1) . '' . + // '
' . print_r($matches, true) . '' + // ); + + $url = $matches[1]; + + // die('
' . var_dump($url, true) . ''); $page2 = ''; @@ -71,14 +114,12 @@ class Fred { $page2 = @file_get_contents($url); } - - echo '
'; var_dump($page2); echo ''; - die(); + preg_match("`url='.*/user/([^']+)/'`isU", $page2, $matches); - $json = $page2; + $gchangeId = $matches[1]; - return $page1; + return $gchangeId; } } \ No newline at end of file diff --git a/lib/Gchange.class.php b/lib/Gchange.class.php index fd5187d..a5281a9 100644 --- a/lib/Gchange.class.php +++ b/lib/Gchange.class.php @@ -1,6 +1,7 @@ _id . '.json'; + $placesCacheFile = $user->getUserGchangeId() . '.json'; $json = $this->getJsonFromCache($placesCacheDir, $placesCacheFile, $this->cacheLongevity['placesNearby']); if (empty($json)) { - $json = $this->getNearbyPlacesJson($user->_source->geoPoint->lat, $user->_source->geoPoint->lon, RADIUS); + $json = $this->getNearbyPlacesJson($user->getLat(), $user->getLon(), $radius); $this->cacheJson($placesCacheDir, $placesCacheFile, $json); @@ -142,7 +143,7 @@ class Gchange { } public function getNearbyPlaces ($lat, $lon, $maxDistance, $minDistance = NULL) { - + $json = $this->getNearbyPlacesJson($lat, $lon, $maxDistance, $minDistance); $result = json_decode($json); diff --git a/lib/GchangeUser.class.php b/lib/GchangeUser.class.php new file mode 100644 index 0000000..06abf47 --- /dev/null +++ b/lib/GchangeUser.class.php @@ -0,0 +1,60 @@ +userGchangeId = $gchangeObject->_id; + + $this->userName = $gchangeObject->_source->title; + + if (isset($gchangeObject->_source->geoPoint->lat, $gchangeObject->_source->geoPoint->lon)) { + + $this->lat = $gchangeObject->_source->geoPoint->lat; + $this->lon = $gchangeObject->_source->geoPoint->lon; + } + + if (isset($gchangeObject->_source->avatar->_content) and + !empty($gchangeObject->_source->avatar->_content)) { + + + $this->avatarImgSrc = 'data:'. $gchangeObject->_source->avatar->_content_type .';base64,' . $gchangeObject->_source->avatar->_content; + } + } + + public function getUserGchangeId () { + + return $this->userGchangeId; + } + + public function getUserName () { + + return $this->userName; + } + + public function getLat () { + + return $this->lat; + } + + public function getLon () { + + return $this->lon; + } + + public function getAvatarImgSrc () { + + return $this->avatarImgSrc; + } +} \ No newline at end of file diff --git a/lib/Message.class.php b/lib/Message.class.php new file mode 100644 index 0000000..cf59560 --- /dev/null +++ b/lib/Message.class.php @@ -0,0 +1,71 @@ +direction = $direction; + + $this->title = $jaklisObject->title; + + $this->date = $jaklisObject->date; + + $contents = preg_replace("`(?[^\n]*`", '', $jaklisObject->content); + $contents = preg_replace("`(\n\s?){2,}`", '', $contents); + $contents = preg_replace("`^(\n\s?)+`", '', $contents); + $this->contents = $contents; + + $this->gchangeId = $jaklisObject->id; + + $this->penpalPubkey = $jaklisObject->pubkey; + } + + public function getDirection () { + + return $this->direction; + } + + public function getMessage () { + + return $this->msg; + } + + public function getTitle () { + + return $this->title; + } + + public function getDate () { + + return $this->date; + } + + public function getPenpalPubkey () { + + return $this->penpalPubkey; + } + + public function getGchangeId() { + + return $this->gchangeId; + } + + public function getContents() { + + return $this->contents; + } +} \ No newline at end of file diff --git a/lib/Messenger.class.php b/lib/Messenger.class.php new file mode 100644 index 0000000..6ea18eb --- /dev/null +++ b/lib/Messenger.class.php @@ -0,0 +1,106 @@ +gchange = $gchange; + } + + public function addMessages ($msgIn, $msgOut) { + + foreach ($msgIn as $m) { + + if (!isset($this->conversations[$m->pubkey])) { + + $this->conversations[$m->pubkey] = new Conversation(); + } + + $msg = new Message($m, 'in'); + + $this->conversations[$msg->getPenpalPubkey()]->addMessage($msg); + + $this->feedUserBase($msg->getPenpalPubkey()); + } + + foreach ($msgOut as $m) { + + if (!isset($this->conversations[$m->pubkey])) { + + $this->conversations[$m->pubkey] = new Conversation(); + } + + $msg = new Message($m, 'out'); + + $this->conversations[$m->pubkey]->addMessage($msg); + + $this->feedUserBase($msg->getPenpalPubkey()); + } + + foreach ($this->conversations as $conv) { + + $conv->sortMessages(); + + $this->checkIfIsLatestMessage($conv->getLastMessage()); + } + } + + public function checkIfIsLatestMessage ($msg) { + + if (!isset($this->latestMessage)) { + + $this->latestMessage = $msg; + + } else { + + if ($msg->getDate() > $this->getLatestMessage()->getDate()) { + + $this->latestMessage = $msg; + } + + } + } + + public function getLatestMessage () { + + return $this->latestMessage; + } + + public function feedUserBase ($penpalPubkey) { + + if (!isset($users[$penpalPubkey])) { + + $this->users[$penpalPubkey] = $this->gchange->getUser($penpalPubkey); + } + } + public function getConversation ($penpalGchangeId) { + + return $this->conversations[$penpalGchangeId]; + } + + public function getConversations () { + + return $this->conversations; + } + + public function getUser ($pubkey) { + + return $this->users[$pubkey]; + } + + public function getLastConversation () { + + return array_reverse($this->conversations)[0]; + } +} \ No newline at end of file diff --git a/login.php b/login.php index c7d186b..13316a5 100644 --- a/login.php +++ b/login.php @@ -1,17 +1,25 @@ donneMoiSaPutaindeG1Pub($_POST['salt'], $_POST['pepper']); + + $_SESSION['player_pubkey'] = $playerG1Id; $gchange = new Gchange(); $user = $gchange->getUser($_SESSION['player_pubkey']); $_SESSION['player_lat'] = $user->_source->geoPoint->lat; $_SESSION['player_lon'] = $user->_source->geoPoint->lon; + $_SESSION['radius'] = DEFAULT_RADIUS; + + $_SESSION['salt'] = $_POST['salt']; + $_SESSION['pepper'] = $_POST['pepper']; header('Location:map.php'); @@ -22,7 +30,9 @@ if (isset($_POST['player'])) { include_once('header.php'); echo ' -